/**
 * 通用样式
 */

@import '../common/variables.scss';
@import '../common/layout.scss';
@import '../common/components.scss';
@import '../common/_transitions.scss';

// 通用页面容器样式
.common-page-container {
  @extend .page-container;
  padding: $spacing-md;
}

// 通用卡片样式
.common-content-card {
  background-color: $white;
  border-radius: $border-radius-base;
  margin-bottom: $spacing-md;
}

// 通用表单样式
.common-form-container {
  @extend .form-container;
  max-width: 650px;
}

// 通用弹窗样式
.common-modal-form {
  max-width: 650px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

// 通用错误容器样式
.common-error-container {
  @include flex-center;
  padding: $spacing-xl 0;
}

// 通用表格操作样式
.common-table-operations {
  @extend .table-operations;
  margin-bottom: $spacing-md;
}

// 通用搜索表单样式
.common-search-form {
  @extend .search-form;
}

/* ===========================
   组件通用样式
   =========================== */

// 搜索表单组件样式
.common-search-form-component {
  margin-bottom: $spacing-md;
  padding: $spacing-md;
  background-color: $white;
  border-radius: $border-radius-base;
  
  :deep(.ant-form) {
    // 表单项样式
    .ant-form-item {
      margin-bottom: $spacing-md;
      
      .ant-form-item-label {
        padding-bottom: $spacing-xs;
        width: 80px; // 固定label宽度
        
        label {
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
      
      .ant-form-item-control {
        flex: 1;
        
        .ant-form-item-control-input {
          width: 100%;
        }
      }
      
      // 统一控件样式
      .ant-input,
      .ant-select,
      .ant-picker,
      .ant-tree-select {
        width: 100%;
      }
    }
    
    // Row 样式调整
    .ant-row {
      margin-bottom: -$spacing-md;  // 抵消最后一行的 margin-bottom
    }
  }
  
  // 操作按钮区域
  .form-actions {
    display: flex;
    justify-content: flex-start; // 按钮左对齐
    padding-top: $spacing-md;
    margin-top: $spacing-md;
    
    .ant-btn {
      min-width: 80px;
      
      .anticon {
        margin-right: $spacing-xs;
      }
    }
  }
}

// 表格操作区组件样式
.common-table-operations-component {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: $spacing-md;
  
  .left-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    
    button {
      margin-right: $spacing-sm;
    }

    .selected-count {
      margin-right: 8px;
    }
    
  }
  
  .right-actions {
    display: flex;
    align-items: center;
    
    button {
      margin-right: $spacing-sm;
    }
  }
  
  .selected-count {
    color: $primary-color;
    font-weight: 500;
  }
  
  .selected-info {
    color: rgba(0, 0, 0, 0.45);
  }
  
  .action-buttons {
    display: flex;
    gap: $spacing-sm;
    
    button {
      margin-right: $spacing-sm;
      
      &:last-child {
        margin-right: 0;
      }
    }
  }
}

// 表格组件通用样式
.common-table-component {
  width: 100%;
  
  :deep(.ant-table) {
    border-radius: $border-radius-base;
    
    .ant-table-thead > tr > th {
      background-color: #fafafa;
      font-weight: 500;
      padding: $spacing-sm $spacing-md;
    }
    
    .ant-table-tbody > tr > td {
      padding: $spacing-sm $spacing-md;
    }
    
    .ant-table-pagination {
      margin: $spacing-md 0;
    }
  }
  
  .status-tag {
    min-width: 60px;
    text-align: center;
  }
  
  .action-column {
    display: flex;
    justify-content: flex-start;
    gap: 4px;
    
    :deep(.ant-btn) {
      padding-left: 2px;
      padding-right: 2px;

      &[type="link"] {
        &.ant-btn-dangerous {
          color: $error-color;
        }
      }
    }
  }
}

// 表单弹窗组件通用样式
.common-form-modal-component {
  :deep(.ant-modal-body) {
    padding: $spacing-md $spacing-lg;
  }
  
  :deep(.ant-form-item) {
    margin-bottom: $spacing-md;
  }
  
  :deep(.ant-form-item-label) {
    padding-bottom: $spacing-xs;
  }
  
  .form-footer {
    display: flex;
    justify-content: flex-end;
    gap: $spacing-sm;
    margin-top: $spacing-md;
  }
}

// 其他特殊组件样式
.common-icon-selector {
  .icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: $spacing-sm;
    max-height: 400px;
    overflow-y: auto;
    padding: $spacing-md;
  }
  
  .icon-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: $spacing-sm;
    border-radius: $border-radius-base;
    cursor: pointer;
    transition: all $transition-duration;
    
    &:hover {
      background-color: rgba($primary-color, 0.1);
    }
    
    &.selected {
      background-color: rgba($primary-color, 0.2);
      color: $primary-color;
    }
    
    .icon {
      font-size: 24px;
      margin-bottom: $spacing-sm;
    }
    
    .icon-name {
      font-size: 12px;
      text-align: center;
      word-break: break-all;
    }
  }
}

/* ===========================
   按钮和表单通用样式
   =========================== */

// 按钮通用样式
:deep(.ant-btn) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  
  .anticon {
    margin-right: 2px;
    font-size: 12px;
  }
  
  &.ant-btn-sm {
    font-size: $font-size-sm;
    
    .anticon {
      font-size: 12px;
      margin-right: 2px;
    }
  }
  
  &.ant-btn-lg {
    font-size: $font-size-lg;
  }
}

// 表单通用样式
:deep(.ant-form-item-label) {
  padding-bottom: $spacing-xs;
  
  label {
    font-size: $font-size-base;
    color: $text-color-secondary;
  }
}

:deep(.ant-form-item-control-input) {
  min-height: 32px;
}

:deep(.ant-select), 
:deep(.ant-picker), 
:deep(.ant-input),
:deep(.ant-input-number),
:deep(.ant-cascader-picker) {
  width: 100%;
}

:deep(.ant-input-search) {
  .ant-input-search-button {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ===========================
   兼容旧样式
   =========================== */

// 搜索区域（旧）
.search-area,
.search-form {
  margin-bottom: $spacing-md;
  background-color: $white;
  border-radius: $border-radius-base;
  padding: $spacing-md;
  
  .search-row,
  .form-row {
    display: flex;
    flex-wrap: wrap;
    gap: $spacing-sm;
    align-items: flex-end;
    
    .form-col {
      margin-right: $spacing-md;
      margin-bottom: $spacing-sm;
    }
    
    :deep(.ant-form-item) {
      margin-bottom: $spacing-sm;
      margin-right: 0;
    }
  }
  
  .form-btns {
    margin-top: $spacing-sm;
    margin-bottom: $spacing-sm;
    
    button {
      margin-right: $spacing-sm;
    }
  }
}

// 表格操作区样式（旧）
.table-operations {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: $spacing-md;
  
  .selected-count {
    color: $primary-color;
    font-weight: 500;
  }
  
  .operation-buttons, 
  .operation-btn {
    display: flex;
    gap: $spacing-sm;
    
    button {
      margin-right: $spacing-sm;
      
      &:last-child {
        margin-right: 0;
      }
    }
  }
  
  .selected-info {
    color: rgba(0, 0, 0, 0.45);
  }
}

// 表格通用样式（旧）
.w-full,
.role-table,
.menu-table,
.dept-table {
  width: 100%;
  
  :deep(.ant-table-thead > tr > th) {
    background-color: #fafafa;
    font-weight: 500;
    padding: $spacing-sm $spacing-md;
  }
  
  :deep(.ant-table-tbody > tr > td) {
    padding: $spacing-sm $spacing-md;
  }
  
  :deep(.ant-table-pagination) {
    margin: $spacing-md 0;
  }
  
  .table-actions {
    display: flex;
    justify-content: flex-start;
    gap: $spacing-sm;
    
    a, button {
      color: $primary-color;
      
      &.danger {
        color: $error-color;
      }
    }
  }
}

// 角色搜索表单（旧）
.role-search-form,
.menu-search-form {
  margin-bottom: $spacing-md;
  background-color: $white;
  border-radius: $border-radius-base;
  padding: $spacing-md;

  .ant-form-item {
    margin-bottom: $spacing-sm;
  }
  
  .ant-form-item-control-input {
    min-height: 32px;
  }
  
  .ant-btn {
    margin-right: $spacing-sm;
  }
}

// 图标选择器（旧）
.icon-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: $spacing-md;
  max-height: 400px;
  overflow-y: auto;
  padding: $spacing-md;
}

.icon-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: $spacing-sm;
  border-radius: $border-radius-base;
  cursor: pointer;
  transition: all $transition-duration;
  
  &:hover {
    background-color: rgba($primary-color, 0.1);
  }
  
  &.icon-selected {
    background-color: rgba($primary-color, 0.2);
    color: $primary-color;
  }
  
  .anticon {
    font-size: 24px;
    margin-bottom: $spacing-sm;
  }
  
  .icon-name {
    font-size: 12px;
    text-align: center;
    word-break: break-all;
  }
}

// 表单弹窗（旧）
.dept-form-modal {
  .ant-form-item {
    margin-bottom: $spacing-md;
  }
}

// 日期范围选择器样式
:deep(.ant-picker-range) {
  width: 100%;
  
  .ant-picker-input {
    width: calc(50% - 20px);
  }
  
  .ant-picker-range-separator {
    padding: 0 $spacing-xs;
  }
}

// 搜索表单中的日期选择器样式
.common-search-form-component,
.search-form,
.role-search-form,
.menu-search-form {
  :deep(.ant-picker) {
    width: 100%;
  }
  
  :deep(.ant-picker-range) {
    min-width: 220px;
  }
}

/* ===========================
   分页控件样式
   =========================== */

:deep(.ant-pagination) {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin: $spacing-md 0;
  flex-wrap: wrap;
  
  @media (max-width: 768px) {
    justify-content: center;
  }
  
  .ant-pagination-total-text {
    margin-right: 16px;
    color: rgba(0, 0, 0, 0.65);
    
    @media (max-width: 576px) {
      width: 100%;
      margin-right: 0;
      margin-bottom: 8px;
      text-align: center;
    }
  }
  
  .ant-pagination-prev,
  .ant-pagination-next,
  .ant-pagination-item,
  .ant-pagination-jump-prev,
  .ant-pagination-jump-next {
    margin-right: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    line-height: 30px;
    border-radius: 4px;
    transition: all 0.3s;
    
    @media (max-width: 576px) {
      margin-right: 4px;
      min-width: 28px;
      height: 28px;
      line-height: 26px;
    }
    
    &:hover {
      border-color: $primary-color;
      color: $primary-color;
      
      .ant-pagination-item-link {
        color: $primary-color;
        border-color: $primary-color;
      }
    }
    
    &:last-child {
      margin-right: 8px;
      
      @media (max-width: 576px) {
        margin-right: 4px;
      }
    }
    
    .ant-pagination-item-link {
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 4px;
      transition: all 0.3s;
      height: 100%;
      width: 100%;
    }
  }
  
  .ant-pagination-item {
    a {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100%;
      padding: 0;
    }
    
    &-active {
      background-color: $primary-color;
      border-color: $primary-color;
      
      a {
        color: $white;
      }
      
      &:hover {
        background-color: lighten($primary-color, 5%);
        
        a {
          color: $white;
        }
      }
    }
  }
  
  .ant-pagination-options {
    display: flex;
    align-items: center;
    margin-left: 16px;
    
    @media (max-width: 576px) {
      margin-left: 0;
      margin-top: 8px;
      width: 100%;
      justify-content: center;
    }
    
    .ant-pagination-options-size-changer {
      margin-right: 16px;
      
      @media (max-width: 576px) {
        margin-right: 8px;
      }
      
      .ant-select-selector {
        border-radius: 4px;
        height: 32px;
        
        @media (max-width: 576px) {
          height: 28px;
        }
        
        .ant-select-selection-item {
          line-height: 30px;
          
          @media (max-width: 576px) {
            line-height: 26px;
          }
        }
      }
    }
    
    .ant-pagination-options-quick-jumper {
      display: flex;
      align-items: center;
      height: 32px;
      color: rgba(0, 0, 0, 0.65);
      
      @media (max-width: 576px) {
        height: 28px;
      }
      
      input {
        margin: 0 8px;
        width: 50px;
        height: 32px;
        text-align: center;
        border-radius: 4px;
        transition: all 0.3s;
        
        @media (max-width: 576px) {
          width: 40px;
          height: 28px;
          margin: 0 4px;
        }
        
        &:hover, &:focus {
          border-color: $primary-color;
        }
      }
    }
  }
}

// 表格内的分页样式
.common-table-component {
  :deep(.ant-table-pagination) {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin: $spacing-md 0;
    padding-right: $spacing-md;
    flex-wrap: wrap;
    
    @media (max-width: 768px) {
      justify-content: center;
      padding-right: 0;
    }
    
    .ant-pagination-total-text {
      margin-right: 16px;
      color: rgba(0, 0, 0, 0.65);
      
      @media (max-width: 576px) {
        width: 100%;
        margin-right: 0;
        margin-bottom: 8px;
        text-align: center;
      }
    }
    
    .ant-pagination-prev,
    .ant-pagination-next,
    .ant-pagination-item,
    .ant-pagination-jump-prev,
    .ant-pagination-jump-next {
      margin-right: 8px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-width: 32px;
      height: 32px;
      line-height: 30px;
      border-radius: 4px;
      transition: all 0.3s;
      
      @media (max-width: 576px) {
        margin-right: 4px;
        min-width: 28px;
        height: 28px;
        line-height: 26px;
      }
      
      &:hover {
        border-color: $primary-color;
        color: $primary-color;
        
        .ant-pagination-item-link {
          color: $primary-color;
          border-color: $primary-color;
        }
      }
      
      &:last-child {
        margin-right: 8px;
        
        @media (max-width: 576px) {
          margin-right: 4px;
        }
      }
      
      .ant-pagination-item-link {
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 4px;
        transition: all 0.3s;
        height: 100%;
        width: 100%;
      }
    }
    
    .ant-pagination-item {
      a {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100%;
        padding: 0;
      }
      
      &-active {
        background-color: $primary-color;
        border-color: $primary-color;
        
        a {
          color: $white;
        }
        
        &:hover {
          background-color: lighten($primary-color, 5%);
          
          a {
            color: $white;
          }
        }
      }
    }
    
    .ant-pagination-options {
      display: flex;
      align-items: center;
      margin-left: 16px;
      
      @media (max-width: 576px) {
        margin-left: 0;
        margin-top: 8px;
        width: 100%;
        justify-content: center;
      }
      
      .ant-pagination-options-size-changer {
        margin-right: 16px;
        
        @media (max-width: 576px) {
          margin-right: 8px;
        }
        
        .ant-select-selector {
          border-radius: 4px;
          height: 32px;
          
          @media (max-width: 576px) {
            height: 28px;
          }
          
          .ant-select-selection-item {
            line-height: 30px;
            
            @media (max-width: 576px) {
              line-height: 26px;
            }
          }
        }
      }
      
      .ant-pagination-options-quick-jumper {
        display: flex;
        align-items: center;
        height: 32px;
        color: rgba(0, 0, 0, 0.65);
        
        @media (max-width: 576px) {
          height: 28px;
        }
        
        input {
          margin: 0 8px;
          width: 50px;
          height: 32px;
          text-align: center;
          border-radius: 4px;
          transition: all 0.3s;
          
          @media (max-width: 576px) {
            width: 40px;
            height: 28px;
            margin: 0 4px;
          }
          
          &:hover, &:focus {
            border-color: $primary-color;
          }
        }
      }
    }
  }
}

/* ===========================
   自定义分页组件样式
   =========================== */

.pagination-wrapper {
  display: flex;
  justify-content: flex-end;
  margin: 16px 0;
  padding-right: 16px;
  
  @media (max-width: 768px) {
    justify-content: center;
    padding-right: 0;
  }
  
  .pagination-component {
    // 样式会继承全局定义的分页样式
  }
}

// 确保表格内的自定义分页组件与表格对齐
.common-table-component {
  .pagination-wrapper {
    margin-top: 16px;
  }
} 